package com.nifostasky.fragment;
/**
 * 设置界面
 */

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.nifostasky.comic.AboutActivity;
import com.nifostasky.comic.R;
import com.nifostasky.utilDao.SettingInfo;


public class MainFragment2 extends Fragment {
    //声明控件
    private Button mbtn_setPage = null;
    private Button mbtn_setView = null;
    private Button mbtn_about = null;
    //数据库的引用
    private SettingInfo set = null;
    //视图
    View view  = null;
    /**
     * 获取view界面
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //获取视图
        view = inflater.inflate(R.layout.activity_main_fragment2,null);
        //获取控件
        mbtn_setPage = view.findViewById(R.id.btn_setPage);
        mbtn_setView = view.findViewById(R.id.btn_setView);
        mbtn_about = view.findViewById(R.id.btn_about);
        //实例化数据库
        set = new SettingInfo(view.getContext());
        //设置按键点击事件
        setListeners();


        return view;
    }

    //活动
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    //设置按键点击事件
    private void setListeners(){
        MainFragment2.Listener listener = new MainFragment2.Listener();
        mbtn_setView.setOnClickListener(listener);
        mbtn_setPage.setOnClickListener(listener);
        mbtn_about.setOnClickListener(listener);
    }

    //点击事件实现
    private class Listener implements View.OnClickListener{
        String url = null;
        boolean flag = false;
        boolean isValid = false;
        @Override
        public void onClick(View v) {
            Intent intent = null;

            // 按键事件定义
            switch (v.getId()){
                case R.id.btn_setPage:
                   if(set.updatevolumePage()){
                       Toast.makeText(view.getContext(), "音量键翻页已经启用", Toast.LENGTH_SHORT).show();
                   }else {
                       Toast.makeText(view.getContext(), "音量键翻页已经关闭", Toast.LENGTH_SHORT).show();
                   }
                    break;
                case R.id.btn_setView:
                    if(set.updateShowKey()){
                        Toast.makeText(view.getContext(), "下方按钮已经显示", Toast.LENGTH_SHORT).show();
                    }else {
                        Toast.makeText(view.getContext(), "下方按钮已经隐藏", Toast.LENGTH_SHORT).show();
                    }
                    break;
                case R.id.btn_about:
                    intent = new Intent();
                    intent.setClass(MainFragment2.this.view.getContext(), AboutActivity.class);
                    startActivity(intent);
                    break;
            }


        }
    }

}
